package com.example.lzy.listviewsample.com.example.lzy.listviewsample.zdy;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.example.lzy.listviewsample.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SimpleAdapterActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.simpleadapter_layout);

        ListView listView = (ListView) findViewById(R.id.listview);

        SimpleAdapter adapter = new SimpleAdapter(this,getData(),R.layout.simpleadapter_item,new String[]{"img","title","info"},new int[]{R.id.img,R.id.text1,R.id.text2});
        listView.setAdapter(adapter);
    }
    private List<Map<String,Object>> getData(){

        List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();

        Map<String,Object> map = new HashMap<String, Object>();
        map.put("img",R.drawable.one_icon);
        map.put("title","1");
        map.put("info","woshishui");
        list.add(map);

        Map<String,Object> map2 = new HashMap<String, Object>();
        map2.put("img",R.drawable.two_icon);
        map2.put("title","2");
        map2.put("info","woshishui");
        list.add(map2);

        Map<String,Object> map3 = new HashMap<String, Object>();
        map3.put("img",R.drawable.one_icon);
        map3.put("title","3");
        map3.put("info","woshishui");
        list.add(map3);
        return list;

    }
}
